package io.mft.dev.base.config;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.hutool.core.util.ObjectUtil;
import io.mft.commons.config.ConfigProvider;
import io.mft.commons.config.ConfigProvider.Env;

public class LocalApplicationEnvConfigProvideLoader extends LocalApplicationCustomizeConfigNamespaceConfigProvideLoader{
	public LocalApplicationEnvConfigProvideLoader(ClassLoader classLoader) {
		super(classLoader, ConfigProvider.DEFAULT_CONFIG_NAMESPACE);
	}
	@Override
	public Map<String, Object> load() {
		String profilesActiveKey="spring.profiles.active";
		/**
		String active="";
		if (classLoader instanceof PluginClassLoader) {
			active=ConfigProvider.get(classLoader.getParent(),ConfigProvider.DEFAULT_CONFIG_NAMESPACE,profilesActiveKey,Env.Prod.name());
		}else {
			active=ConfigProvider.get(classLoader,ConfigProvider.DEFAULT_CONFIG_NAMESPACE,profilesActiveKey,Env.Prod.name());
		}**/
		String active=ConfigProvider.getHostProgramConfigValue(profilesActiveKey,Env.Prod.name());
		if (ObjectUtil.isNotEmpty(active)) {
			String path=ConfigProvider.DEFAULT_CONFIG_NAMESPACE+"-"+active+".yml";
			Map<String, Object> configObjectMap=parseYaml(classLoader, path);
			return configObjectMap;
		}else {
			Map<String, Object> kv=new ConcurrentHashMap<String, Object>();
			return kv;
		}
	}
}
